package com.os.osframe.scaffold.create;

import com.os.osframe.scaffold.domain.ScaffoldXmlTable;
import com.os.osframe.scaffold.util.PropertyConfigurerLoader;

import javax.annotation.Resource;
import java.io.File;

/**
 * Created by wangdc on 2015-4-27.
 */
public class CreateJsCode extends BaseCreate implements ICreateCode {
    public CreateJsCode(){

    }
    public CreateJsCode(ScaffoldXmlTable scaffoldXmlTable){
        super(scaffoldXmlTable);
    }
    public void create(String packages)throws Exception{
        System.out.println("=====开始生成jsp页面=====");
        //String path = replaceStr(new File("").getAbsolutePath(), "\\", "/");//获取项目的根路径，这里获取到的是softdp的路径
        String basePath = (String) getPropertyConfigurer().getProperty("osframe.file.path");//获取属性配置的服务器路径
        if (basePath.substring(basePath.length() - 1).equals("/")) {
            basePath = basePath.substring(basePath.length() - 1);
        }//System.out.println(path);//E:/java/intelijwork/softdp
        String targetFilePath=basePath;
        targetFilePath+="/auto/code/"+packages.replaceAll("\\.","/")+"/js/resource";
        //System.out.println(targetFilePath);
        String tempPath = replaceStr(new File(this.getClass().getResource("").getPath()).getAbsolutePath(), "\\", "/");//获取当前类所在路径
        if(tempPath.indexOf("create")>-1){
            tempPath=tempPath.substring(0,tempPath.length()-7);
        }
        tempPath+="/js";
        //System.out.println(tempPath);
        //xmlObjList= ReadXmlObj.getDataInfoByModule(module, packages);//获取列表对象
        createFile(tempPath,targetFilePath);
    }

    /**
     *
     * @param srcText
     * @return
     * @throws Exception
     */
    @Override
    protected String replaceCode(String srcText) throws Exception{
//        if(scaffoldXmlTable==null ||scaffoldXmlTable.getStatus()==null || "false".equals(scaffoldXmlTable.getStatus())){
//            return srcText;
//        }
//        srcText=replaceEdit(srcText,scaffoldXmlTable);
//        srcText=replaceView(srcText,scaffoldXmlTable);
//        srcText=replaceList(srcText,scaffoldXmlTable);

        return srcText;
    }

    /**
     * 替换编辑页面
     * @param srcText
     * @param scaffoldXmlTable
     * @return
     * @throws Exception
     */
    protected String replaceEdit(String srcText,ScaffoldXmlTable scaffoldXmlTable) throws Exception{

        return srcText;
    }
    /**
     * 替换查看页面
     * @param srcText
     * @param scaffoldXmlTable
     * @return
     * @throws Exception
     */
    protected String replaceView(String srcText,ScaffoldXmlTable scaffoldXmlTable) throws Exception{

        return srcText;
    }
    /**
     * 替换列表页面
     * @param srcText
     * @param scaffoldXmlTable
     * @return
     * @throws Exception
     */
    protected String replaceList(String srcText,ScaffoldXmlTable scaffoldXmlTable) throws Exception{

        return srcText;
    }
}
